/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lily
 * Date: 2024-09-20
 * Time: 11:39
 */
public class product_ExceptSelf {
    public int[] productExceptSelf(int[] nums) {
        int n = nums.length;
        int[] dpl = new int[n];
        int[] dpr = new int[n];
        dpl[0] = 1;
        dpr[n - 1] = 1;
        for (int i = 1; i < n; i++) {
            dpl[i] = dpl[i - 1] * nums[i-1];
        }
        for (int i = n - 2; i >= 0; i--) {
            dpr[i] = dpr[i + 1] * nums[i+1];
        }

        int[] ret = new int[n];
        for (int i = 0; i < n; i++) {
            ret[i] = dpl[i] * dpr[i];
        }
        return ret;
    }
}
